﻿namespace eProject.Model
{
    public class Activity
    {
        #region Constructor

        public Activity(Task task, Employee employee, Period period, int priority, string description)
        {           
            Task = task;
            Employee = employee;
            Period = period;
            Priority = priority;
            Description = description ?? "";
        }

        public Activity()
        {
            
        }

        #endregion

        #region Properties

        public Task Task { get; set; }

        public Employee Employee { get; set; }

        public Period Period
        {
            get { return _period; } 
            set
            {
                if (value == _period) return;
                var oldValue = _period;
                _period = value;
                InvokePeriodChanged(this, oldValue);
            }
        }

        public int Priority
        {
            get { return _priority; } 
            set
            {
                if (value == _priority) return;
                _priority = value;
                InvokePriorityChanged(this);
            }
        }

        public string Description { get; set; }

        #endregion

        #region Events

        internal event EventHandler<Activity,Period> PeriodChanged;

        internal event EventHandler<Activity> PriorityChanged;

        #endregion

        #region Private Methods

        private void InvokePeriodChanged(Activity activity, Period oldPeriod)
        {
            var changed = PeriodChanged;
            if (changed != null) changed(activity, oldPeriod);
        }

        private void InvokePriorityChanged(Activity activity)
        {
            var changed = PriorityChanged;
            if (changed != null) changed(activity);
        }

        #endregion

        #region Fields

        private Period _period;

        private int _priority;

        #endregion

    }
}
